<?php
/* @var $this AdsPlanController */
/* @var $model AdsPlan */

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\assets\AppAsset;  





$this->registerCssFile('http://poker.520code.cc/basic/jedate/skin/jedate.css',['depends' => [\yii\web\JqueryAsset::className()]]);   

$this->registerJsFile('http://poker.520code.cc/basic/jedate/jquery.jedate.js',['depends' => [\yii\web\JqueryAsset::className()]]);  
$this->registerJsFile('https://code.highcharts.com/highcharts.js',['depends' => [\yii\web\JqueryAsset::className()]]);  
$this->registerJsFile('https://code.highcharts.com/modules/exporting.js',['depends' => [\yii\web\JqueryAsset::className()]]);  





?>

<div id="pagelet-platform" style="margin-top: 80px; font-size: 15px;">



<table id="w0" class="table table-striped table-bordered detail-view"><tbody>
<tr><th>用户名称</th><td><?= $model->name ?></td></tr>
<tr><th>用户id</th><td><?= $model->user_id ?></td></tr>
<tr><th>用户手机</th><td><?= $model->phone ?></td></tr>

</tbody></table>




<div>
<ol class="breadcrumb">
  选择需要查询的时间范围
</ol>
</div>

<div>

<input style="width:180px;float: left;padding-left: 10px;" id="AdsPlan_day_start" name="AdsPlan[day_start]" type="text" value="" class="hasDatepicker">
<p style="
    float: left;
    width: 38px;
    text-align: center;
">至</p>
<input style="width: 180px;float: left;padding-left: 10px;" id="AdsPlan_day_end" name="AdsPlan[day_end]" type="text" value="" class="hasDatepicker">


<button type="button" class="btn btn-success" onclick="get_shenhe();" style="
    margin-left: 10px;
    min-width: 80px;
">查询</button>
</div>





<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>


<div>
<ol class="breadcrumb">
  <span id="day_start"></span>至<span id="day_end"></span>的数据
</ol>
</div>

<table id="w0" class="table table-striped table-bordered detail-view"><tbody>
<tr><th>总战绩</th><td id="all_score"> </td></tr>
<tr><th>总结算</th><td id="all_in_score"> </td></tr>
<tr><th>总反水</th><td id="all_out_score"> </td></tr>
<tr><th>总最终结算</th><td id="all_end_score"> </td></tr>
<tr><th>总局数</th><td id="all_count"> </td></tr>
<tr><th>成绩方差</th><td id="all_va"> </td></tr>
<tr><th>成绩均值</th><td id="all_avg"> </td></tr>

</tbody></table>



<div class="grid-24">
                 

            <div class="widget widget-table">
				     <div class="widget-header">
						 <h3 class="icon chart">数据</h3>
					 </div>
					 <div class="widget-content">
                         <table id="campaignlistt" class="table table-bordered table-striped">
						     <thead>
							     <tr>
                                    <th>时间</th>
                                     
                                     <th>昵称</th>
                                     <th>桌号</th>

                                  
                                     <th>战绩</th>
                                     <th>客人结算</th>
                                     <th>反水</th>
                                     <th>最终结算</th>
                                     <th>代理</th>
                                     <th>操作</th>
							     </tr>
						     </thead>
						     <tbody id="table_div">
  
                            </tbody>
					    </table>
    
</div>
    <!-- .widget-content -->
    </div> <!-- .widget -->
    
    </div>
<script src="/basic/web/assets/31f45ab6/jquery.js"></script>

<script type="text/javascript">
	


    $(document).ready(function(){

          $("#AdsPlan_day_start").jeDate({
          isinitVal:true,
          festival:true,
          
          format:"YYYY-MM-DD",
        
        });
         var day_start = new Date(new Date().getTime()-20*24*60*60*1000 ).format("yyyy-MM-dd");
        $("#AdsPlan_day_start").val(day_start);

        $("#AdsPlan_day_end").jeDate({
          isinitVal:true,
          festival:true,
          
          format:"YYYY-MM-DD",
        
        });

        get_shenhe();

    });



function get_shenhe(node) {
	// var adv = $("#adv").val();

  var adv ='玩家';
	var day_start = $("#AdsPlan_day_start").val();
	var day_end = $("#AdsPlan_day_end").val();



  $("#day_start").html(day_start);
  $("#day_end").html(day_end);


  var id = <?=  $model->user_id ?>;
	

	// console.log(adv);
	// console.log(day_start);
	// console.log(day_end);


	$.ajax({
            url: "/basic/web/index.php?r=user-poker/myscore-ajax&id="+id+"&start_day="+day_start+"&end_day="+day_end,
            dataType: 'json',
            data:'',
            cache: false,
            success: function(data) {
            	$("#table_div").empty();

                var chart_data_req  = [];
                var chart_data_get  = [];
                var chart_data_show  = [];
                var chart_data_click  = [];

                var all_score = 0;
                var all_end_score = 0;
                var all_in_score = 0;
                var all_out_score = 0 ;

                var all_sc = [];

                for (var i = 0; i < data.length; i++) {

                	var info =  data[i];
                	// console.log(info);
                  var day_ =  info.ts.split(' ')[0].split('-');
                  chart_data_req.push([Date.UTC(day_[0], day_[1]-1, day_[2]), parseInt(info.end_score)]);
                  chart_data_get.push([Date.UTC(day_[0], day_[1]-1, day_[2]), parseInt(info.in_score)]);
                  chart_data_show.push([Date.UTC(day_[0], day_[1]-1, day_[2]), parseInt(info.out_score)]);
                  chart_data_click.push([Date.UTC(day_[0], day_[1]-1, day_[2]), parseInt(info.score)]);
	               
                 all_score += parseInt(info.score);
                 all_out_score += parseInt(info.out_score);
                 all_in_score += parseInt(info.in_score);
                 all_end_score += parseInt(info.end_score);

                 all_sc.push(parseInt(info.score));


                  if(parseInt(info.end_score)<min_value){
                    min_value = parseInt(info.end_score);
                  }

                  if(parseInt(info.in_score)<min_value){
                    min_value = parseInt(info.in_score);
                  }

                  if(parseInt(info.out_score)<min_value){
                    min_value = parseInt(info.out_score);
                  }

                  if(parseInt(info.score)<min_value){
                    min_value = parseInt(info.score);
                  }

                   var html_ =          '<tr class="gradeA">'
                             +         '<td class="center">'+info.ts.split(' ')[0]+'</td>'
                             +         '<td class="center">'+info.name+'</td>'
                             +         '<td class="center">'+info.table_id+'</td>'

                             +         '<td class="center">'+info.score.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'</td>'
                             +         '<td class="center">'+info.in_score.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'</td>'
                             +         '<td class="center">'+info.out_score.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'</td>'
                             +         '<td class="center">'+info.end_score.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'</td>'
                             +         '<td class="center">'+info.agent_name+'</td>'
                             +         '<td class="center"><button type="button" class="btn btn-success" onclick="view('+info.poker_id+');" >查看</button> <button type="button" class="btn btn-primary" onclick="edit('+info.poker_id+');" >编辑</button> <a href="/basic/web/index.php?r=user-poker%2Fdelete&id='+info.poker_id+'" title="Delete" aria-label="Delete" data-confirm="Are you sure you want to delete this item?" data-method="post" data-pjax="0"><button type="button" class="btn btn-danger" >删除</button></a>'+'</td>'
                             
                            ;


	                $("#table_div").append(html_);
            	}

              $("#all_in_score").html((all_in_score+"").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
              $("#all_out_score").html((all_out_score+"").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
              $("#all_end_score").html((all_end_score+"").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
              $("#all_score").html((all_score+"").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
              $("#all_va").html(variance(all_sc));
              $("#all_count").html(data.length);
              

              


              chart(adv,chart_data_req,chart_data_get,chart_data_show,chart_data_click);

            }
        });


} 




function view(id){
  window.location.href = "/basic/web/index.php?r=user-poker%2Fview&id="+id;
}

function edit(id){
  window.location.href = "/basic/web/index.php?r=user-poker%2Fupdate&id="+id; 
}

function vdelete(id){
  window.location.href = "/basic/web/index.php?r=user-poker%2Fdelete&id="+id;
}

var min_value = 0;

//方差计算
function variance(numbers) {  
    var mean = 0;  
    var sum = 0;  
    for(var i=0;i<numbers.length;i++){  
        sum += numbers[i];  
    }  
    mean = sum / numbers.length;  
    $("#all_avg").html(mean);
    sum = 0;  
    for(var i=0;i<numbers.length;i++){  
        sum += Math.pow(numbers[i] - mean , 2);  
    }  
    return sum / numbers.length;  
};


function chart(adv,chart_data_req,chart_data_get,chart_data_show,chart_data_click) {
  

  Highcharts.chart('container', {
    chart: {
        type: 'line'
    },
    title: {
        text: adv+"玩家数据图"
    },
    subtitle: {
        text: adv+"成绩收成反水"
    },
    xAxis: {
        // type: 'datetime',
        // dateTimeLabelFormats: { // don't display the dummy year
        //     month: '%e. %b',
        //     year: '%b'
        // },
        type: 'datetime',
                labels: {
                    format: '{value:%m-%d}',
        },
        title: {
            text: 'Date'
        }
    },
    yAxis: {
        title: {
            text: '收成数据'
        },
        min: min_value
    },
    // tooltip: {
    //     headerFormat: '<b>{series.name}</b><br>',
    //     pointFormat: '{point.x:%m}: {point.y:.0f} '
    // },

    plotOptions: {
        // spline: {
        //     marker: {
        //         enabled: true
        //     }
        // }
         line: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: false
        }
    },

    series: [
    {
        name: adv+"最终结算",
        // Define the data points. All series have a dummy year
        // of 1970/71 in order to be compared on the same x axis. Note
        // that in JavaScript, months start at 0 for January, 1 for February etc.
        data: chart_data_req
    }, 
        {
        name: adv+"客人结算",
        // Define the data points. All series have a dummy year
        // of 1970/71 in order to be compared on the same x axis. Note
        // that in JavaScript, months start at 0 for January, 1 for February etc.
        data: chart_data_get
    }, 
    {
        name: adv+"反水",
        data: chart_data_show
    }, {
        name: adv+"成绩",
        data: chart_data_click
    }]
});

}


Date.prototype.format = function(format) {
       var date = {
              "M+": this.getMonth() + 1,
              "d+": this.getDate(),
              "h+": this.getHours(),
              "m+": this.getMinutes(),
              "s+": this.getSeconds(),
              "q+": Math.floor((this.getMonth() + 3) / 3),
              "S+": this.getMilliseconds()
       };
       if (/(y+)/i.test(format)) {
              format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
       }
       for (var k in date) {
              if (new RegExp("(" + k + ")").test(format)) {
                     format = format.replace(RegExp.$1, RegExp.$1.length == 1
                            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
              }
       }
       return format;
}

</script>